Best Time to Buy and Sell Stock 2 发表于 2019-03-14 | 分类于 贪心 , leetcode https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ 12345678910111213class Solution {public: int maxProfit(vector<int>& prices) { int n=prices.size(); int sum=0;//定义利润 for(int i=1;i<n;i++) { if(prices[i]-prices[i-1]>0) sum+=prices[i]-prices[i-1]; } return sum; }};